import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, JoinColumn } from 'typeorm';
import { ProductEntity } from './Product.entity';
import dayjs from 'dayjs';

@Entity({ name: 'evaluates' })
class Evaluate {
  @PrimaryGeneratedColumn({ zerofill: true })
  evaluateId: number;

  @Column('int', { width: 10 })
  userId: number;

  @Column('tinyint', { width: 5 })
  star: number;

  @Column({ length: 100 })
  detailText: string;

  @Column('date', { default: dayjs().format('YYYY-MM-DD') })
  date: Date;


  @ManyToOne(() => ProductEntity, product => product.evaluates, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'fkProductId' })
  product: ProductEntity;
}

export {
  Evaluate as EvaluateEntity
};